import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 双指针
 */
public class Leetcode189 {
    public static void main(String[] args) {
        int[] k = {1, 2, 3, 4, 5, 6};
        rotate1(k, 2);
        System.out.println(Arrays.toString(k));
    }

    public static void rotate(int[] nums, int k) {
        k = k % nums.length;

        int[] res = new int[nums.length];
        int resIndex = 0;
        for (int i = nums.length - k; i < nums.length; i++) {
            res[resIndex] = nums[i];
            resIndex++;
        }

        for (int i = 0; i < nums.length - k; i++) {
            res[resIndex] = nums[i];
            resIndex++;
        }

        System.arraycopy(res, 0, nums, 0, res.length);
    }

    public static void rotate1(int[] nums, int k) {
        List<Integer> list = Arrays.stream(nums).boxed().collect(Collectors.toList());
        Collections.rotate(list, k);
        int[] m =new int[nums.length];
    }
}
